<?php
    include_once "fbaccess.php";
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

        <title>Facebook</title>    

        <title>shadela</title>    

		<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    </head>
<body>
<?php
function time_elapsed($time) {
	sscanf($time,"%u-%u-%uT%u:%u:%u+0000",$year,$month,$day,$hour,$min,$sec);
    $time_seconds = time() - ((int)substr(date('O'),0,3)*60*60) - mktime($hour,$min,$sec,$month,$day,$year);
    
    if($time_seconds < 1) return '0 seconds';
    
    $arr = array(12*30*24*60*60	=> 'year',
                30*24*60*60		=> 'month',
                24*60*60		=> 'day',
                60*60			=> 'hour',
                60				=> 'minute',
                1				=> 'second'
                );
    
    foreach($arr as $secs => $str){
        $d = $time_seconds / $secs;
        if($d >= 1){
            $r = floor($d);
            return $r . ' ' . $str . ($r > 1 ? 's' : '');
        }
    }
}


?>

<div id="bar">
	<div class="top-area">
		<div class="side-box" >

			<div class="logout" >
				<?php				
				if ($user) echo '<a href="' . $logoutUrl . '"><h5>Logout</h5></a>';
				else echo '<a href="' . $loginUrl . '"><h5>Login</h5></a>';
				?>
			</div>
		</div>
	</div>
</div>

<?php if(!$user) { ?>

<div class="login-box">
<div id="f-connect-button"><a href="<?=$loginUrl?>"><img src="images/f-connect.png" alt="Connect to your Facebook Account"/></a></div>

</div>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/zh_CN/all.js#xfbml=1&appId=131092957054643";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>

<?php // } else { ?>
<div class="big-container" >

		<div class="left-sidebar">		
			<div class="profile-pic"><img src="https://graph.facebook.com/<?php echo($user); ?>/picture?type=large"/></div>
			<div class="sidebar-title">
				<h3><a>Friends (<?php echo(count($friends_list['data'])); ?>)</a></h3>
			<?php
			$i=1;
			foreach($friends_list['data'] as $frnd)	{
					echo '<div class="friend-list" ><div class="friend-thumb"><img src="https://graph.facebook.com/'. $frnd['id'] .'/picture"/></div><div class="friend-name" ><strong><a>' . $frnd['name'] . '</a></strong></div></div>';
					if(++$i > 10) break;
			}
			?>
			</div>				
		</div>
	<div class="temp">
		<div class="container" >
			<div class="main" >
				<div class="user-info">
				<h1><?php echo($user_info['name']);?></h1>
				<div class="profile-info">
					<?php
				if(isset($user_info['gender'])) echo "<b>   GENDER : </b>" . $user_info['gender'];
				if(isset($user_info['birthday'])) echo "<b>   BIRTHDAY : </b>" . $user_info['birthday'];
				if(isset($user_info['education']))
					{
						echo "<b>   EDUCATION : </b>";
						foreach($user_info['education'] as $school)
							{
								echo $school['school']['name'];								
								break;									
							}
					}
				if(isset($user_info['hometown'])) echo "<b>   HOMETOWN : </b>" . $user_info['hometown']['name'];
					?>				
				</div>
				</div>
				<div class="like">
				
<div id="fb-root"></div>
<script>(function(d){
  var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js#appId=131092957054643&xfbml=1";
  d.getElementsByTagName('head')[0].appendChild(js);
}(document));</script>
<div class="fb-like1" data-href="http://dev.shadela.com/ceshi/fb" data-send="false" data-layout="box_count" data-width="55" data-show-faces="false"></div>

</div>
				
				<div class="status-update1">
					<h3>Update Status</h3>					
					<form name="" action="<?=$site_url?>" method="post">
					<textarea id="status" name="status"></textarea>
					<?php if(isset($statusUpdate)) echo'<div class="status-success-message" ><h4 style="padding-left:20px;padding-top:4px;">Status Updated Successfully.</h4></div>'; ?>
					<input id="post-button" type="image" name="submit" src="images/post.jpg" />
					</form>
					<form name="pub" id="pub" action="<?=$site_url?>" method="post">
					<input type="hidden" name="pub" value="25 labs">					
					<input id="publish-button" type="image" name="publish" src="images/post-25-labs.jpg" />
					</form>
				</div>
				
	
			</div>			
		</div>		
	
	</div>
	
</div>

<?php } ?>
  <iframe id="ifm" src="http://www.facebook.com/plugins/like.php?href=http://dev.shadela.com/ceshi/fb/index.php"
			        scrolling="no" frameborder="0"
			        style="border:none; width:450px; height:80px"></iframe>

</body>
</html>